<template>
  <div>
    <h1>当前求和为:{{ $store.state.sum }}</h1>

    <h1>放大十倍当前求和为:{{ $store.getters.bigSum}}</h1>

    <h1>学校:{{ $store.state.school}}</h1>
    <h1>科目:{{ $store.state.subject}}</h1>

    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increase(n)">+</button>
    <button @click="decrease(n)">-</button>
    <button @click="increaseOdd(n)">当前求和奇数再加</button>
    <button @click="increaseWait(n)">等一等再加</button>
  </div>
</template>

<script>
import { mapState ,mapGetters,mapMutations,mapActions} from 'vuex';
export default {
  name: "Count",
  data() {
    return {
      n: 1
    };
  },
  computed: {
    // sum() {
    //   return this.$store.state.sum;
    // },
    // school() {
    //   return this.$store.state.school;
    // },
    // subject() {
    //   return this.$store.state.subject;
    // },
    
    //对象写法
    // ...mapState({sum:'sum',school:"school",subject:"subject"}),
    // ...mapGetters({bigSum:'bigSum'})

    //数组写法
    ...mapState(["sum","school","subject"]),
    ...mapGetters(["bigSum"])
  },
  methods: {
    // increase() {
    //   this.$store.commit("JIA", this.n);
    // },
    // decrease() {
    //   this.$store.commit("JIAN", this.n);
    // },
    //对象写法
    ...mapMutations({"increase":"JIA","decrease":"JIAN"}),

    //数组写法
    // ...mapMutations(["JIA","JIAN"]),//increase(n)->改成JIA(n)等

    // increaseOdd() {
    //   this.$store.dispatch("odd", this.n);
    // },
    // increaseWait() {
    //   this.$store.dispatch("wait", this.n);
    // }
    //对象写法
    ...mapActions({"increaseOdd":"odd","increaseWait":"wait"})

    //数组写法
    // ...mapActions(["odd","wait"]),//increaseOdd(n)->改成odd(n) 等

  }
};
</script>
<style scoped>
button {
  margin-left: 10px;
}
</style>
